package com.library.service;

import com.library.dao.BookDao;
import com.library.entity.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookDao bookDao;

    @Override
    public List<Book> getAllBooks() {
        return bookDao.findAll();
    }

    @Override
    public void addBook(Book book) {
        bookDao.insertBook(book);
    }

    @Override
    public void updateBook(Book book) {
        bookDao.updateBook(book);
    }

    @Override
    public void deleteBook(int bookid) {
        bookDao.deleteBook(bookid);
    }

    @Override
    public Book getBookById(int bookid) {
        return bookDao.findById(bookid);
    }

    @Override
    public List<Book> getBooksByPage(int offset, int pageSize) {
        return bookDao.findByPage(offset, pageSize);
    }

    @Override
    public int getTotalCount() {
        return bookDao.countAll();
    }
}